import {IMyObject, MyObject} from "./MyObject";
import { SubjectType } from "./Subject";

export type GradeType = SubjectType

export interface IGrade extends IMyObject {
  /**
   * 分数的原始值
   */
  num: number;

  /**
   * 分数的类型
   */
  type: SubjectType;
}

export class Grade extends MyObject  implements IGrade{
  num = 0
  type: SubjectType = SubjectType.None;

  constructor(type: SubjectType, num:number) {
    // console.log("construct")
    super()
    this.num = num
    this.type = type

    this.initName();
  }

  private initName() {
    switch (this.type) {
      case SubjectType.None:
        this.name = "无"
        break;
      case SubjectType.Chinese:
        this.name = "语文"
        break;
      case SubjectType.English:
        this.name = "英语"
        break;
      case SubjectType.Math:
        this.name = "数学"
        break;
      case SubjectType.Physical:
        this.name = "物理"
        break;
      case SubjectType.Chemistry:
        this.name = "化学"
        break;
      case SubjectType.Biology:
        this.name = "生物"
        break;
    }
  }

  toString(): string {
    switch (this.type){
      default:
      case SubjectType.None:
       return "没有成绩"
      case SubjectType.Chinese:
        return this.toChineseGrade();
      case SubjectType.English:
        return this.toEnglishGrade();
      case SubjectType.Math:
      case SubjectType.Biology:
      case SubjectType.Chemistry:
      case SubjectType.Physical:
        return this.num.toString()
    }
  }

  private toChineseGrade() {
    if(this.num > 90){
      return "优"
    }else if(this.num > 80) {
      return "良"
    } else if(this.num > 60) {
      return "中"
    } else {
      return  "差"
    }
  }
  private toEnglishGrade() {
    if(this.num > 90){
      return "A"
    }else if(this.num > 80) {
      return "B"
    } else if(this.num > 60) {
      return "C"
    } else {
      return  "D"
    }
  }
}